#include "../include/snakegameentrywidget.h"
#include "../include/config.h"
#include <QDebug>
#include <QApplication>
#include <QDir>
#include <QStandardPaths>
#include <QShowEvent>
#include <QResizeEvent>
#include <QFile>
#include <QGraphicsOpacityEffect>
#include <QtMath>
#include <QMessageBox>

SnakeGameEntryWidget::SnakeGameEntryWidget(QWidget *parent)
    : QWidget(parent)
    , m_mainLayout(nullptr)
    , m_leftPanel(nullptr)
    , m_rightPanel(nullptr)
    , m_leftContainer(nullptr)
    , m_leftSubContainer(nullptr)
    , m_skinButton(nullptr)
    , m_leftSpacer(nullptr)
    , m_snakeDisplay(nullptr)
    , m_gameModePanel(nullptr)
    , m_snakeHead(nullptr)
    , m_snakeBody1(nullptr)
    , m_snakeBody2(nullptr)
    , m_snakeBody3(nullptr)
    , m_snakeTail(nullptr)
    , m_singlePlayerBtn(nullptr)
    , m_multiPlayerBtn(nullptr)
    , m_roomModeBtn(nullptr)
    , m_snakeAnimationTimer(new QTimer(this))
    , m_animationStep(0)
    , m_serverPort(0)
{
    setWindowTitle("Snake Game - 选择游戏模式");
    setMinimumSize(1000, 600);
    resize(1200, 700);
    
    // 加载蛇图片资源
    loadSnakeImages();
    
    // 初始化UI
    setupUI();
    
    // 设置样式
    setupStyleSheet();
    
    // 连接动画定时器
    connect(m_snakeAnimationTimer, &QTimer::timeout, this, &SnakeGameEntryWidget::updateSnakeAnimation);
}

SnakeGameEntryWidget::~SnakeGameEntryWidget()
{
    stopSnakeAnimation();
}

void SnakeGameEntryWidget::setGameSession(const QString &sessionToken, const QString &serverHost, int serverPort)
{
    m_sessionToken = sessionToken;
    m_serverHost = serverHost;
    m_serverPort = serverPort;

    // 设置属性，以便MainWindow可以访问
    setProperty("sessionToken", sessionToken);
    setProperty("serverHost", serverHost);
    setProperty("serverPort", serverPort);

    qDebug() << "SnakeGameEntryWidget: 设置游戏会话信息";
    qDebug() << "  服务器:" << serverHost << ":" << serverPort;
    qDebug() << "  会话令牌长度:" << sessionToken.length();
    qDebug() << "  会话令牌前10字符:" << sessionToken.left(10);

    // 验证属性是否正确设置
    QString verifyToken = property("sessionToken").toString();
    QString verifyHost = property("serverHost").toString();
    int verifyPort = property("serverPort").toInt();

    qDebug() << "SnakeGameEntryWidget: 验证属性设置";
    qDebug() << "  属性sessionToken长度:" << verifyToken.length();
    qDebug() << "  属性serverHost:" << verifyHost;
    qDebug() << "  属性serverPort:" << verifyPort;
}

void SnakeGameEntryWidget::showEvent(QShowEvent *event)
{
    QWidget::showEvent(event);
    startSnakeAnimation();
}

void SnakeGameEntryWidget::resizeEvent(QResizeEvent *event)
{
    QWidget::resizeEvent(event);
    // 可以在这里调整蛇的位置和大小
}

void SnakeGameEntryWidget::setupUI()
{
    // === 创建主布局（垂直布局，卡片式设计）===
    m_mainLayout = new QVBoxLayout(this);
    m_mainLayout->setContentsMargins(30, 30, 30, 30);
    m_mainLayout->setSpacing(25);

    // === 创建顶部欢迎卡片 ===
    createWelcomeCard();

    // === 创建中部内容区域 ===
    createContentArea();

    // === 创建底部状态卡片 ===
    createStatusCard();

    // === 应用统一样式 ===
    applyModernStyle();

    setLayout(m_mainLayout);
}

QWidget* SnakeGameEntryWidget::createLeftPanel()
{
    QWidget *panel = new QWidget();
    panel->setObjectName("leftPanel");

    // === 创建左侧的水平布局（左右两个容器等高）===
    QHBoxLayout *leftMainLayout = new QHBoxLayout(panel);
    leftMainLayout->setContentsMargins(0, 0, 0, 0);
    leftMainLayout->setSpacing(0);  // 间距为0

    // === 创建皮肤按钮容器（左侧）===
    m_leftSubContainer = new QWidget();
    m_leftSubContainer->setObjectName("leftSubContainer");

    QVBoxLayout *skinLayout = new QVBoxLayout(m_leftSubContainer);
    skinLayout->setContentsMargins(0, 0, 0, 0);  // 内边距为0
    skinLayout->setSpacing(0);  // 间距为0

    // 创建皮肤按钮
    m_skinButton = new QPushButton("🎨 皮肤");
    m_skinButton->setObjectName("skinButton");
    m_skinButton->setMinimumSize(100, 40);
    m_skinButton->setMaximumSize(120, 50);
    connect(m_skinButton, &QPushButton::clicked, this, &SnakeGameEntryWidget::onSkinButtonClicked);

    skinLayout->addWidget(m_skinButton);

    // 添加弹簧，将皮肤按钮顶到左上角
    m_leftSpacer = new QSpacerItem(20, 40, QSizePolicy::Minimum, QSizePolicy::Expanding);
    skinLayout->addItem(m_leftSpacer);

    // === 创建蛇展示容器（右侧）===
    m_snakeDisplay = createSnakeDisplay();

    // === 添加到左侧主布局（等高度）===
    leftMainLayout->addWidget(m_leftSubContainer, 1);  // 皮肤按钮容器
    leftMainLayout->addWidget(m_snakeDisplay, 1);      // 蛇展示容器

    return panel;
}

QWidget* SnakeGameEntryWidget::createRightPanel()
{
    QWidget *panel = new QWidget();
    panel->setObjectName("rightPanel");

    // === 创建右侧的纵向布局（三个容器纵向分布）===
    QVBoxLayout *rightLayout = new QVBoxLayout(panel);
    rightLayout->setContentsMargins(20, 20, 20, 20);
    rightLayout->setSpacing(25);

    // === 创建三个纵向分布的容器 ===

    // 上部容器：功能按钮（排行榜、设置、帮助）
    QWidget *topContainer = new QWidget();
    topContainer->setObjectName("rightTopContainer");
    topContainer->setFixedHeight(80);
    setupRightTopContainer(topContainer);

    // 中部容器：三个游戏模式（单人、多人、大逃杀）
    QWidget *middleContainer = new QWidget();
    middleContainer->setObjectName("rightMiddleContainer");
    setupRightMiddleContainer(middleContainer);

    // 下部容器：游戏信息和状态
    QWidget *bottomContainer = new QWidget();
    bottomContainer->setObjectName("rightBottomContainer");
    bottomContainer->setFixedHeight(100);
    setupRightBottomContainer(bottomContainer);

    // === 添加到右侧布局 ===
    rightLayout->addWidget(topContainer);           // 上部容器：功能按钮
    rightLayout->addWidget(middleContainer, 1);     // 中部容器：游戏模式（主要内容）
    rightLayout->addWidget(bottomContainer);        // 下部容器：游戏信息

    return panel;
}

QWidget* SnakeGameEntryWidget::createSnakeDisplay()
{
    QWidget *display = new QWidget();
    display->setObjectName("snakeDisplay");
    display->setMinimumHeight(200);
    
    // 使用网格布局来精确控制蛇的位置
    QGridLayout *snakeLayout = new QGridLayout(display);
    snakeLayout->setContentsMargins(0, 0, 0, 0);  // 内边距为0
    snakeLayout->setSpacing(5);
    
    // 创建蛇的各个部分
    m_snakeHead = new QLabel();
    m_snakeBody1 = new QLabel();
    m_snakeBody2 = new QLabel();
    m_snakeBody3 = new QLabel();
    m_snakeTail = new QLabel();
    
    // 设置对象名称用于样式
    m_snakeHead->setObjectName("snakeHead");
    m_snakeBody1->setObjectName("snakeBody");
    m_snakeBody2->setObjectName("snakeBody");
    m_snakeBody3->setObjectName("snakeBody");
    m_snakeTail->setObjectName("snakeTail");
    
    // 设置固定大小
    QSize segmentSize(40, 40);
    m_snakeHead->setFixedSize(segmentSize);
    m_snakeBody1->setFixedSize(segmentSize);
    m_snakeBody2->setFixedSize(segmentSize);
    m_snakeBody3->setFixedSize(segmentSize);
    m_snakeTail->setFixedSize(segmentSize);
    
    // 设置对齐方式
    m_snakeHead->setAlignment(Qt::AlignCenter);
    m_snakeBody1->setAlignment(Qt::AlignCenter);
    m_snakeBody2->setAlignment(Qt::AlignCenter);
    m_snakeBody3->setAlignment(Qt::AlignCenter);
    m_snakeTail->setAlignment(Qt::AlignCenter);
    
    // 设置图片或文本（如果没有图片的话）
    if (!m_snakeHeadPixmap.isNull()) {
        m_snakeHead->setPixmap(m_snakeHeadPixmap.scaled(segmentSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
        m_snakeBody1->setPixmap(m_snakeBodyPixmap.scaled(segmentSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
        m_snakeBody2->setPixmap(m_snakeBodyPixmap.scaled(segmentSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
        m_snakeBody3->setPixmap(m_snakeBodyPixmap.scaled(segmentSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
        m_snakeTail->setPixmap(m_snakeTailPixmap.scaled(segmentSize, Qt::KeepAspectRatio, Qt::SmoothTransformation));
    } else {
        // 如果没有图片，使用文本表示
        m_snakeHead->setText("🐍");
        m_snakeBody1->setText("⬜");
        m_snakeBody2->setText("⬜");
        m_snakeBody3->setText("⬜");
        m_snakeTail->setText("⬜");
    }
    
    // 水平排列蛇（从左到右：尾巴 -> 身体 -> 头部）
    snakeLayout->addWidget(m_snakeTail, 1, 0, Qt::AlignCenter);
    snakeLayout->addWidget(m_snakeBody3, 1, 1, Qt::AlignCenter);
    snakeLayout->addWidget(m_snakeBody2, 1, 2, Qt::AlignCenter);
    snakeLayout->addWidget(m_snakeBody1, 1, 3, Qt::AlignCenter);
    snakeLayout->addWidget(m_snakeHead, 1, 4, Qt::AlignCenter);
    
    // 设置列拉伸，使蛇居中
    snakeLayout->setColumnStretch(0, 1);
    snakeLayout->setColumnStretch(1, 0);
    snakeLayout->setColumnStretch(2, 0);
    snakeLayout->setColumnStretch(3, 0);
    snakeLayout->setColumnStretch(4, 0);
    snakeLayout->setColumnStretch(5, 1);
    
    // 设置行拉伸，使蛇垂直居中
    snakeLayout->setRowStretch(0, 1);
    snakeLayout->setRowStretch(1, 0);
    snakeLayout->setRowStretch(2, 1);
    
    return display;
}



QPushButton* SnakeGameEntryWidget::createGameModeButton(const QString &title, const QString &description,
                                                       const QString &icon, const QString &color)
{
    QPushButton *button = new QPushButton();
    button->setObjectName("gameModeButton");
    button->setMinimumSize(200, 120);
    button->setMaximumSize(250, 150);

    // 创建按钮内容
    QString buttonText = QString(
        "<div style='text-align: center;'>"
        "<div style='font-size: 24px; margin-bottom: 8px;'>%1</div>"
        "<div style='font-size: 16px; font-weight: bold; color: %2; margin-bottom: 5px;'>%3</div>"
        "<div style='font-size: 12px; color: #666; line-height: 1.2;'>%4</div>"
        "</div>"
    ).arg(icon, color, title, description);

    button->setText(buttonText);
    button->setProperty("themeColor", color);

    return button;
}

void SnakeGameEntryWidget::loadSnakeImages()
{
    // 尝试从资源文件夹加载图片
    QString resourcePath = QApplication::applicationDirPath() + "/resources/images/snake/";

    qDebug() << "SnakeGameEntryWidget: 尝试加载蛇图片资源";
    qDebug() << "  资源路径:" << resourcePath;

    // 加载蛇头图片
    QString headPath = resourcePath + "snake_head.png";
    if (QFile::exists(headPath)) {
        m_snakeHeadPixmap.load(headPath);
        qDebug() << "  ✅ 蛇头图片加载成功:" << headPath;
    } else {
        qDebug() << "  ❌ 蛇头图片不存在:" << headPath;
    }

    // 加载蛇身图片
    QString bodyPath = resourcePath + "snake_body.png";
    if (QFile::exists(bodyPath)) {
        m_snakeBodyPixmap.load(bodyPath);
        qDebug() << "  ✅ 蛇身图片加载成功:" << bodyPath;
    } else {
        qDebug() << "  ❌ 蛇身图片不存在:" << bodyPath;
    }

    // 加载蛇尾图片
    QString tailPath = resourcePath + "snake_tail.png";
    if (QFile::exists(tailPath)) {
        m_snakeTailPixmap.load(tailPath);
        qDebug() << "  ✅ 蛇尾图片加载成功:" << tailPath;
    } else {
        qDebug() << "  ❌ 蛇尾图片不存在:" << tailPath;
    }
}

void SnakeGameEntryWidget::startSnakeAnimation()
{
    if (!m_snakeAnimationTimer->isActive()) {
        m_animationStep = 0;
        m_snakeAnimationTimer->start(800); // 每800ms更新一次
        qDebug() << "SnakeGameEntryWidget: 启动蛇动画";
    }
}

void SnakeGameEntryWidget::stopSnakeAnimation()
{
    if (m_snakeAnimationTimer->isActive()) {
        m_snakeAnimationTimer->stop();
        qDebug() << "SnakeGameEntryWidget: 停止蛇动画";
    }
}

void SnakeGameEntryWidget::updateSnakeAnimation()
{
    // 简单的呼吸动画效果
    m_animationStep = (m_animationStep + 1) % 4;

    double opacity = 0.7 + 0.3 * qSin(m_animationStep * M_PI / 2);

    // 应用透明度效果到蛇头
    if (m_snakeHead) {
        QGraphicsOpacityEffect *effect = new QGraphicsOpacityEffect();
        effect->setOpacity(opacity);
        m_snakeHead->setGraphicsEffect(effect);
    }
}

// === 槽函数实现 ===
void SnakeGameEntryWidget::onSkinButtonClicked()
{
    qDebug() << "SnakeGameEntryWidget: 皮肤按钮被点击";
    emit skinSettingsRequested();
}

void SnakeGameEntryWidget::onSinglePlayerClicked()
{
    qDebug() << "SnakeGameEntryWidget: 选择单人模式";
    emit gameModeSelected("single");
}

void SnakeGameEntryWidget::onMultiPlayerClicked()
{
    qDebug() << "SnakeGameEntryWidget: 选择多人模式";
    emit gameModeSelected("multi");
}

void SnakeGameEntryWidget::onRoomModeClicked()
{
    qDebug() << "SnakeGameEntryWidget: 选择房间模式";
    emit gameModeSelected("room");
}

void SnakeGameEntryWidget::setupStyleSheet()
{
    QString styleSheet = R"(
        /* === 主窗口样式 === */
        SnakeGameEntryWidget {
            background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
                stop:0 #1a1a2e, stop:0.5 #16213e, stop:1 #0f3460);
            border: none;
        }

        /* === 左侧面板样式 === */
        QWidget#leftPanel {
            background: transparent;
            border: none;
        }

        QWidget#leftSubContainer {
            background: rgba(255, 255, 255, 0.05);
            border: none;
            border-radius: 15px;
            max-width: 200px;
        }

        /* === 皮肤按钮样式 === */
        QPushButton#skinButton {
            background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                stop:0 #667eea, stop:1 #764ba2);
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 14px;
            font-weight: bold;
            padding: 8px 16px;
        }

        QPushButton#skinButton:hover {
            background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                stop:0 #7c8ef0, stop:1 #8a5fb8);
            transform: translateY(-2px);
        }

        QPushButton#skinButton:pressed {
            background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                stop:0 #5a6fd8, stop:1 #6a4190);
        }

        /* === 右侧面板样式 === */
        QWidget#rightPanel {
            background: transparent;
            border: none;
        }

        /* === 蛇展示区域样式 === */
        QWidget#snakeDisplay {
            background: rgba(255, 255, 255, 0.05);
            border: none;
            border-radius: 20px;
            margin: 10px;
        }

        QLabel#snakeHead {
            background: rgba(76, 175, 80, 0.8);
            border: 2px solid #4CAF50;
            border-radius: 20px;
            font-size: 20px;
        }

        QLabel#snakeBody {
            background: rgba(139, 195, 74, 0.8);
            border: 2px solid #8BC34A;
            border-radius: 18px;
            font-size: 16px;
        }

        QLabel#snakeTail {
            background: rgba(104, 159, 56, 0.8);
            border: 2px solid #689F38;
            border-radius: 16px;
            font-size: 14px;
        }

        /* === 游戏模式面板样式 === */
        QWidget#gameModePanel {
            background: rgba(255, 255, 255, 0.05);
            border: 2px solid rgba(255, 255, 255, 0.1);
            border-radius: 15px;
            margin: 10px;
        }

        /* === 游戏模式按钮样式 === */
        QPushButton#gameModeButton {
            background: rgba(255, 255, 255, 0.1);
            border: 2px solid rgba(255, 255, 255, 0.2);
            border-radius: 12px;
            color: white;
            font-family: "Microsoft YaHei", "SimHei", sans-serif;
            text-align: center;
            padding: 15px;
        }

        QPushButton#gameModeButton:hover {
            background: rgba(255, 255, 255, 0.2);
            border: 2px solid rgba(255, 255, 255, 0.4);
            transform: translateY(-3px);
            box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
        }

        QPushButton#gameModeButton:pressed {
            background: rgba(255, 255, 255, 0.15);
            transform: translateY(-1px);
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
        }

        /* === 动画过渡效果 === */
        QPushButton {
            transition: all 0.3s ease;
        }
    )";

    setStyleSheet(styleSheet);

    qDebug() << "SnakeGameEntryWidget: 样式表设置完成";
}

/**
 * @brief 创建欢迎卡片
 *
 * 顶部欢迎区域，包含游戏标题和简介
 */
void SnakeGameEntryWidget::createWelcomeCard()
{
    QWidget *welcomeCard = new QWidget();
    welcomeCard->setObjectName("welcomeCard");
    welcomeCard->setFixedHeight(120);

    QHBoxLayout *welcomeLayout = new QHBoxLayout(welcomeCard);
    welcomeLayout->setContentsMargins(40, 30, 40, 30);
    welcomeLayout->setSpacing(30);

    // === 左侧：游戏图标和标题 ===
    QWidget *titleSection = new QWidget();
    QHBoxLayout *titleLayout = new QHBoxLayout(titleSection);
    titleLayout->setContentsMargins(0, 0, 0, 0);
    titleLayout->setSpacing(20);

    // 游戏图标
    QLabel *gameIcon = new QLabel("🐍");
    gameIcon->setObjectName("gameIcon");
    gameIcon->setFixedSize(60, 60);
    gameIcon->setAlignment(Qt::AlignCenter);

    // 标题和副标题
    QWidget *titleText = new QWidget();
    QVBoxLayout *titleTextLayout = new QVBoxLayout(titleText);
    titleTextLayout->setContentsMargins(0, 0, 0, 0);
    titleTextLayout->setSpacing(5);

    QLabel *mainTitle = new QLabel("Snake Game");
    mainTitle->setObjectName("mainTitle");

    QLabel *subTitle = new QLabel("经典贪吃蛇游戏 - 选择您的游戏模式");
    subTitle->setObjectName("subTitle");

    titleTextLayout->addWidget(mainTitle);
    titleTextLayout->addWidget(subTitle);

    titleLayout->addWidget(gameIcon);
    titleLayout->addWidget(titleText);
    titleLayout->addStretch();

    // === 右侧：快速操作 ===
    QWidget *quickActions = new QWidget();
    QHBoxLayout *actionsLayout = new QHBoxLayout(quickActions);
    actionsLayout->setContentsMargins(0, 0, 0, 0);
    actionsLayout->setSpacing(15);

    QPushButton *settingsBtn = new QPushButton("⚙️");
    settingsBtn->setObjectName("quickActionBtn");
    settingsBtn->setFixedSize(40, 40);
    settingsBtn->setToolTip("游戏设置");

    QPushButton *helpBtn = new QPushButton("❓");
    helpBtn->setObjectName("quickActionBtn");
    helpBtn->setFixedSize(40, 40);
    helpBtn->setToolTip("游戏帮助");

    actionsLayout->addWidget(settingsBtn);
    actionsLayout->addWidget(helpBtn);

    welcomeLayout->addWidget(titleSection, 1);
    welcomeLayout->addWidget(quickActions);

    m_mainLayout->addWidget(welcomeCard);
}

/**
 * @brief 创建内容区域
 *
 * 中部主要内容区域，包含游戏模式选择和预览
 */
void SnakeGameEntryWidget::createContentArea()
{
    QWidget *contentArea = new QWidget();
    contentArea->setObjectName("contentArea");

    QHBoxLayout *contentLayout = new QHBoxLayout(contentArea);
    contentLayout->setContentsMargins(0, 0, 0, 0);
    contentLayout->setSpacing(25);

    // === 左侧：游戏预览卡片 ===
    createGamePreviewCard(contentLayout);

    // === 右侧：游戏模式选择卡片 ===
    createGameModeCard(contentLayout);

    m_mainLayout->addWidget(contentArea, 1);  // 占主要空间
}

/**
 * @brief 创建状态卡片
 *
 * 底部状态信息区域
 */
void SnakeGameEntryWidget::createStatusCard()
{
    QWidget *statusCard = new QWidget();
    statusCard->setObjectName("statusCard");
    statusCard->setFixedHeight(80);

    QHBoxLayout *statusLayout = new QHBoxLayout(statusCard);
    statusLayout->setContentsMargins(40, 20, 40, 20);
    statusLayout->setSpacing(30);

    // === 服务器状态 ===
    QWidget *serverStatus = new QWidget();
    QHBoxLayout *serverLayout = new QHBoxLayout(serverStatus);
    serverLayout->setContentsMargins(0, 0, 0, 0);
    serverLayout->setSpacing(10);

    QLabel *serverIcon = new QLabel("🟢");
    serverIcon->setFixedSize(20, 20);

    QLabel *serverText = new QLabel("服务器正常");
    serverText->setObjectName("statusText");

    serverLayout->addWidget(serverIcon);
    serverLayout->addWidget(serverText);

    // === 在线玩家 ===
    QWidget *playersStatus = new QWidget();
    QHBoxLayout *playersLayout = new QHBoxLayout(playersStatus);
    playersLayout->setContentsMargins(0, 0, 0, 0);
    playersLayout->setSpacing(10);

    QLabel *playersIcon = new QLabel("👥");
    playersIcon->setFixedSize(20, 20);

    QLabel *playersText = new QLabel("在线玩家: 1,234");
    playersText->setObjectName("statusText");

    playersLayout->addWidget(playersIcon);
    playersLayout->addWidget(playersText);

    // === 延迟信息 ===
    QWidget *pingStatus = new QWidget();
    QHBoxLayout *pingLayout = new QHBoxLayout(pingStatus);
    pingLayout->setContentsMargins(0, 0, 0, 0);
    pingLayout->setSpacing(10);

    QLabel *pingIcon = new QLabel("📡");
    pingIcon->setFixedSize(20, 20);

    QLabel *pingText = new QLabel("延迟: 25ms");
    pingText->setObjectName("statusText");

    pingLayout->addWidget(pingIcon);
    pingLayout->addWidget(pingText);

    statusLayout->addWidget(serverStatus);
    statusLayout->addWidget(playersStatus);
    statusLayout->addWidget(pingStatus);
    statusLayout->addStretch();

    m_mainLayout->addWidget(statusCard);
}

/**
 * @brief 创建游戏预览卡片
 * @param layout 父布局
 */
void SnakeGameEntryWidget::createGamePreviewCard(QHBoxLayout *layout)
{
    QWidget *previewCard = new QWidget();
    previewCard->setObjectName("gameCard");
    previewCard->setMinimumWidth(400);

    QVBoxLayout *previewLayout = new QVBoxLayout(previewCard);
    previewLayout->setContentsMargins(30, 30, 30, 30);
    previewLayout->setSpacing(20);

    // === 卡片标题 ===
    QLabel *previewTitle = new QLabel("游戏预览");
    previewTitle->setObjectName("cardTitle");

    // === 蛇展示区域 ===
    m_snakeDisplay = createSnakeDisplay();
    m_snakeDisplay->setMinimumHeight(200);

    // === 皮肤选择区域 ===
    QWidget *skinSection = new QWidget();
    QHBoxLayout *skinLayout = new QHBoxLayout(skinSection);
    skinLayout->setContentsMargins(0, 0, 0, 0);
    skinLayout->setSpacing(15);

    QLabel *skinLabel = new QLabel("皮肤主题:");
    skinLabel->setObjectName("sectionLabel");

    m_skinButton = new QPushButton("🎨 选择皮肤");
    m_skinButton->setObjectName("modernButton");
    connect(m_skinButton, &QPushButton::clicked, this, &SnakeGameEntryWidget::onSkinButtonClicked);

    skinLayout->addWidget(skinLabel);
    skinLayout->addWidget(m_skinButton);
    skinLayout->addStretch();

    previewLayout->addWidget(previewTitle);
    previewLayout->addWidget(m_snakeDisplay, 1);
    previewLayout->addWidget(skinSection);

    layout->addWidget(previewCard, 2);
}

/**
 * @brief 创建游戏模式卡片
 * @param layout 父布局
 */
void SnakeGameEntryWidget::createGameModeCard(QHBoxLayout *layout)
{
    QWidget *modeCard = new QWidget();
    modeCard->setObjectName("gameCard");
    modeCard->setMinimumWidth(450);

    QVBoxLayout *modeLayout = new QVBoxLayout(modeCard);
    modeLayout->setContentsMargins(30, 30, 30, 30);
    modeLayout->setSpacing(20);

    // === 卡片标题 ===
    QLabel *modeTitle = new QLabel("选择游戏模式");
    modeTitle->setObjectName("cardTitle");

    // === 创建现代化单人模式按钮 ===
    m_singlePlayerBtn = new QPushButton();
    m_singlePlayerBtn->setObjectName("modernGameModeCard");
    m_singlePlayerBtn->setMinimumHeight(100);
    m_singlePlayerBtn->setMaximumHeight(100);

    // 创建按钮内容布局
    QHBoxLayout *singleContentLayout = new QHBoxLayout(m_singlePlayerBtn);
    singleContentLayout->setContentsMargins(25, 20, 25, 20);
    singleContentLayout->setSpacing(20);

    // 图标
    QLabel *singleIcon = new QLabel("🎮");
    singleIcon->setObjectName("modernModeIcon");
    singleIcon->setFixedSize(50, 50);
    singleIcon->setAlignment(Qt::AlignCenter);
    singleIcon->setStyleSheet(
        "QLabel {"
        "   font-size: 32px;"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:1,"
        "       stop:0 rgba(76, 175, 80, 0.4), stop:1 rgba(76, 175, 80, 0.3));"
        "   border: 2px solid rgba(76, 175, 80, 0.7);"
        "   border-radius: 25px;"
        "   color: #ffffff;"
        "}"
    );

    // 文本区域
    QWidget *singleTextArea = new QWidget();
    QVBoxLayout *singleTextLayout = new QVBoxLayout(singleTextArea);
    singleTextLayout->setContentsMargins(0, 0, 0, 0);
    singleTextLayout->setSpacing(5);

    QLabel *singleTitle = new QLabel("单人模式");
    singleTitle->setObjectName("modernModeTitle");
    singleTitle->setStyleSheet(
        "QLabel {"
        "   font-size: 20px;"
        "   font-weight: bold;"
        "   color: #ffffff;"
        "   text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);"
        "}"
    );

    QLabel *singleDesc = new QLabel("挑战自己的极限");
    singleDesc->setObjectName("modernModeDescription");
    singleDesc->setStyleSheet(
        "QLabel {"
        "   font-size: 14px;"
        "   color: rgba(255, 255, 255, 0.85);"
        "   font-weight: 500;"
        "}"
    );

    singleTextLayout->addWidget(singleTitle);
    singleTextLayout->addWidget(singleDesc);

    // 箭头指示器
    QLabel *singleArrow = new QLabel("▶");
    singleArrow->setObjectName("modernModeArrow");
    singleArrow->setFixedSize(25, 25);
    singleArrow->setAlignment(Qt::AlignCenter);
    singleArrow->setStyleSheet(
        "QLabel {"
        "   font-size: 18px;"
        "   color: rgba(76, 175, 80, 0.9);"
        "   font-weight: bold;"
        "}"
    );

    singleContentLayout->addWidget(singleIcon);
    singleContentLayout->addWidget(singleTextArea, 1);
    singleContentLayout->addWidget(singleArrow);

    // 设置按钮样式
    m_singlePlayerBtn->setStyleSheet(
        "QPushButton#modernGameModeCard {"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
        "       stop:0 rgba(76, 175, 80, 0.2), stop:1 rgba(76, 175, 80, 0.15));"
        "   border: 2px solid rgba(76, 175, 80, 0.4);"
        "   border-radius: 20px;"
        "   text-align: left;"
        "   padding: 0px;"
        "   margin: 8px 0px;"
        "}"
        "QPushButton#modernGameModeCard:hover {"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
        "       stop:0 rgba(76, 175, 80, 0.35), stop:1 rgba(76, 175, 80, 0.25));"
        "   border: 2px solid rgba(76, 175, 80, 0.6);"
        "   transform: translateY(-3px);"
        "   box-shadow: 0 8px 25px rgba(76, 175, 80, 0.3);"
        "}"
        "QPushButton#modernGameModeCard:pressed {"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
        "       stop:0 rgba(76, 175, 80, 0.15), stop:1 rgba(76, 175, 80, 0.1));"
        "   transform: translateY(-1px);"
        "}"
    );

    // === 创建现代化多人模式按钮 ===
    m_multiPlayerBtn = new QPushButton();
    m_multiPlayerBtn->setObjectName("modernGameModeCard");
    m_multiPlayerBtn->setMinimumHeight(100);
    m_multiPlayerBtn->setMaximumHeight(100);

    // 创建按钮内容布局
    QHBoxLayout *multiContentLayout = new QHBoxLayout(m_multiPlayerBtn);
    multiContentLayout->setContentsMargins(25, 20, 25, 20);
    multiContentLayout->setSpacing(20);

    // 图标
    QLabel *multiIcon = new QLabel("👥");
    multiIcon->setObjectName("modernModeIcon");
    multiIcon->setFixedSize(50, 50);
    multiIcon->setAlignment(Qt::AlignCenter);
    multiIcon->setStyleSheet(
        "QLabel {"
        "   font-size: 32px;"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:1,"
        "       stop:0 rgba(33, 150, 243, 0.4), stop:1 rgba(33, 150, 243, 0.3));"
        "   border: 2px solid rgba(33, 150, 243, 0.7);"
        "   border-radius: 25px;"
        "   color: #ffffff;"
        "}"
    );

    // 文本区域
    QWidget *multiTextArea = new QWidget();
    QVBoxLayout *multiTextLayout = new QVBoxLayout(multiTextArea);
    multiTextLayout->setContentsMargins(0, 0, 0, 0);
    multiTextLayout->setSpacing(5);

    QLabel *multiTitle = new QLabel("多人模式");
    multiTitle->setObjectName("modernModeTitle");
    multiTitle->setStyleSheet(
        "QLabel {"
        "   font-size: 20px;"
        "   font-weight: bold;"
        "   color: #ffffff;"
        "   text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);"
        "}"
    );

    QLabel *multiDesc = new QLabel("与其他玩家竞技");
    multiDesc->setObjectName("modernModeDescription");
    multiDesc->setStyleSheet(
        "QLabel {"
        "   font-size: 14px;"
        "   color: rgba(255, 255, 255, 0.85);"
        "   font-weight: 500;"
        "}"
    );

    multiTextLayout->addWidget(multiTitle);
    multiTextLayout->addWidget(multiDesc);

    // 箭头指示器
    QLabel *multiArrow = new QLabel("▶");
    multiArrow->setObjectName("modernModeArrow");
    multiArrow->setFixedSize(25, 25);
    multiArrow->setAlignment(Qt::AlignCenter);
    multiArrow->setStyleSheet(
        "QLabel {"
        "   font-size: 18px;"
        "   color: rgba(33, 150, 243, 0.9);"
        "   font-weight: bold;"
        "}"
    );

    multiContentLayout->addWidget(multiIcon);
    multiContentLayout->addWidget(multiTextArea, 1);
    multiContentLayout->addWidget(multiArrow);

    // 设置按钮样式
    m_multiPlayerBtn->setStyleSheet(
        "QPushButton#modernGameModeCard {"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
        "       stop:0 rgba(33, 150, 243, 0.2), stop:1 rgba(33, 150, 243, 0.15));"
        "   border: 2px solid rgba(33, 150, 243, 0.4);"
        "   border-radius: 20px;"
        "   text-align: left;"
        "   padding: 0px;"
        "   margin: 8px 0px;"
        "}"
        "QPushButton#modernGameModeCard:hover {"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
        "       stop:0 rgba(33, 150, 243, 0.35), stop:1 rgba(33, 150, 243, 0.25));"
        "   border: 2px solid rgba(33, 150, 243, 0.6);"
        "   transform: translateY(-3px);"
        "   box-shadow: 0 8px 25px rgba(33, 150, 243, 0.3);"
        "}"
        "QPushButton#modernGameModeCard:pressed {"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
        "       stop:0 rgba(33, 150, 243, 0.15), stop:1 rgba(33, 150, 243, 0.1));"
        "   transform: translateY(-1px);"
        "}"
    );

    // === 创建现代化大逃杀模式按钮 ===
    m_roomModeBtn = new QPushButton();
    m_roomModeBtn->setObjectName("modernGameModeCard");
    m_roomModeBtn->setMinimumHeight(100);
    m_roomModeBtn->setMaximumHeight(100);

    // 创建按钮内容布局
    QHBoxLayout *battleContentLayout = new QHBoxLayout(m_roomModeBtn);
    battleContentLayout->setContentsMargins(25, 20, 25, 20);
    battleContentLayout->setSpacing(20);

    // 图标
    QLabel *battleIcon = new QLabel("⚔️");
    battleIcon->setObjectName("modernModeIcon");
    battleIcon->setFixedSize(50, 50);
    battleIcon->setAlignment(Qt::AlignCenter);
    battleIcon->setStyleSheet(
        "QLabel {"
        "   font-size: 32px;"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:1,"
        "       stop:0 rgba(255, 87, 34, 0.4), stop:1 rgba(255, 87, 34, 0.3));"
        "   border: 2px solid rgba(255, 87, 34, 0.7);"
        "   border-radius: 25px;"
        "   color: #ffffff;"
        "}"
    );

    // 文本区域
    QWidget *battleTextArea = new QWidget();
    QVBoxLayout *battleTextLayout = new QVBoxLayout(battleTextArea);
    battleTextLayout->setContentsMargins(0, 0, 0, 0);
    battleTextLayout->setSpacing(5);

    QLabel *battleTitle = new QLabel("大逃杀模式");
    battleTitle->setObjectName("modernModeTitle");
    battleTitle->setStyleSheet(
        "QLabel {"
        "   font-size: 20px;"
        "   font-weight: bold;"
        "   color: #ffffff;"
        "   text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);"
        "}"
    );

    QLabel *battleDesc = new QLabel("多人生存竞技");
    battleDesc->setObjectName("modernModeDescription");
    battleDesc->setStyleSheet(
        "QLabel {"
        "   font-size: 14px;"
        "   color: rgba(255, 255, 255, 0.85);"
        "   font-weight: 500;"
        "}"
    );

    battleTextLayout->addWidget(battleTitle);
    battleTextLayout->addWidget(battleDesc);

    // 箭头指示器
    QLabel *battleArrow = new QLabel("▶");
    battleArrow->setObjectName("modernModeArrow");
    battleArrow->setFixedSize(25, 25);
    battleArrow->setAlignment(Qt::AlignCenter);
    battleArrow->setStyleSheet(
        "QLabel {"
        "   font-size: 18px;"
        "   color: rgba(255, 87, 34, 0.9);"
        "   font-weight: bold;"
        "}"
    );

    battleContentLayout->addWidget(battleIcon);
    battleContentLayout->addWidget(battleTextArea, 1);
    battleContentLayout->addWidget(battleArrow);

    // 设置按钮样式
    m_roomModeBtn->setStyleSheet(
        "QPushButton#modernGameModeCard {"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
        "       stop:0 rgba(255, 87, 34, 0.2), stop:1 rgba(255, 87, 34, 0.15));"
        "   border: 2px solid rgba(255, 87, 34, 0.4);"
        "   border-radius: 20px;"
        "   text-align: left;"
        "   padding: 0px;"
        "   margin: 8px 0px;"
        "}"
        "QPushButton#modernGameModeCard:hover {"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
        "       stop:0 rgba(255, 87, 34, 0.35), stop:1 rgba(255, 87, 34, 0.25));"
        "   border: 2px solid rgba(255, 87, 34, 0.6);"
        "   transform: translateY(-3px);"
        "   box-shadow: 0 8px 25px rgba(255, 87, 34, 0.3);"
        "}"
        "QPushButton#modernGameModeCard:pressed {"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
        "       stop:0 rgba(255, 87, 34, 0.15), stop:1 rgba(255, 87, 34, 0.1));"
        "   transform: translateY(-1px);"
        "}"
    );

    // === 连接信号槽 ===
    connect(m_singlePlayerBtn, &QPushButton::clicked, this, &SnakeGameEntryWidget::onSinglePlayerClicked);
    // 多人模式和房间模式暂时禁用
    // connect(m_multiPlayerBtn, &QPushButton::clicked, this, &SnakeGameEntryWidget::onMultiPlayerClicked);
    // connect(m_roomModeBtn, &QPushButton::clicked, this, &SnakeGameEntryWidget::onRoomModeClicked);

    modeLayout->addWidget(modeTitle);
    modeLayout->addWidget(m_singlePlayerBtn);
    modeLayout->addWidget(m_multiPlayerBtn);
    modeLayout->addWidget(m_roomModeBtn);

    layout->addWidget(modeCard, 3);
}

// 删除：未使用的createModernModeButton方法

/**
 * @brief 应用现代化样式
 *
 * 使用QSS为整个界面应用统一的现代化样式
 */
void SnakeGameEntryWidget::applyModernStyle()
{
    QString modernStyle = QString(R"(
        /* === 全局样式 === */
        SnakeGameEntryWidget {
            background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                stop:0 #1a1a2e, stop:1 #16213e);
            color: #ffffff;
            font-family: 'Segoe UI', Arial, sans-serif;
        }

        /* === 欢迎卡片样式 === */
        QWidget#welcomeCard {
            background: qlineargradient(x1:0, y1:0, x2:1, y2:0,
                stop:0 rgba(76, 175, 80, 0.15), stop:1 rgba(76, 175, 80, 0.1));
            border: 2px solid rgba(76, 175, 80, 0.3);
            border-radius: 20px;
            margin: 10px;
        }

        /* === 游戏卡片样式 === */
        QWidget#gameCard {
            background: qlineargradient(x1:0, y1:0, x2:0, y2:1,
                stop:0 rgba(255, 255, 255, 0.12), stop:1 rgba(255, 255, 255, 0.08));
            border: 2px solid rgba(255, 255, 255, 0.25);
            border-radius: 25px;
            margin: 10px;
        }

        /* === 状态卡片样式 === */
        QWidget#statusCard {
            background: qlineargradient(x1:0, y1:0, x2:1, y2:0,
                stop:0 rgba(52, 152, 219, 0.15), stop:1 rgba(52, 152, 219, 0.1));
            border: 2px solid rgba(52, 152, 219, 0.3);
            border-radius: 18px;
            margin: 10px;
        }

        /* === 标题样式 === */
        QLabel#gameIcon {
            font-size: 40px;
            background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
                stop:0 #4CAF50, stop:1 #45A049);
            border-radius: 30px;
            border: 3px solid rgba(255, 255, 255, 0.4);
            color: #ffffff;
            font-weight: bold;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
        }

        QLabel#mainTitle {
            font-size: 32px;
            font-weight: bold;
            color: #ffffff;
            margin: 0px;
            text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
        }

        QLabel#subTitle {
            font-size: 15px;
            color: rgba(255, 255, 255, 0.9);
            margin: 0px;
            font-weight: 500;
        }

        QLabel#cardTitle {
            font-size: 22px;
            font-weight: bold;
            color: #ffffff;
            margin-bottom: 15px;
            text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.4);
        }

        QLabel#sectionLabel {
            font-size: 15px;
            color: rgba(255, 255, 255, 0.95);
            font-weight: 600;
        }

        QLabel#statusText {
            font-size: 14px;
            color: rgba(255, 255, 255, 0.9);
            font-weight: 600;
        }

        /* === 快速操作按钮样式 === */
        QPushButton#quickActionBtn {
            background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
                stop:0 rgba(52, 152, 219, 0.4), stop:1 rgba(52, 152, 219, 0.3));
            border: 2px solid rgba(52, 152, 219, 0.5);
            border-radius: 22px;
            font-size: 18px;
            color: #ffffff;
            font-weight: bold;
            padding: 8px 16px;
            text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
        }

        QPushButton#quickActionBtn:hover {
            background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
                stop:0 rgba(52, 152, 219, 0.6), stop:1 rgba(52, 152, 219, 0.5));
            border: 2px solid rgba(52, 152, 219, 0.8);
            transform: scale(1.08);
            box-shadow: 0 6px 20px rgba(52, 152, 219, 0.4);
        }

        QPushButton#quickActionBtn:pressed {
            background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
                stop:0 rgba(52, 152, 219, 0.3), stop:1 rgba(52, 152, 219, 0.2));
            transform: scale(0.95);
        }

        /* === 现代按钮样式 === */
        QPushButton#modernButton {
            background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
                stop:0 rgba(155, 89, 182, 0.8), stop:1 rgba(155, 89, 182, 0.6));
            border: 2px solid rgba(155, 89, 182, 0.5);
            border-radius: 15px;
            color: white;
            font-size: 16px;
            font-weight: bold;
            padding: 12px 24px;
            min-width: 150px;
            text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.4);
        }

        QPushButton#modernButton:hover {
            background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
                stop:0 rgba(155, 89, 182, 0.9), stop:1 rgba(155, 89, 182, 0.7));
            border: 2px solid rgba(155, 89, 182, 0.7);
            transform: translateY(-3px);
            box-shadow: 0 8px 25px rgba(155, 89, 182, 0.4);
        }

        QPushButton#modernButton:pressed {
            background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
                stop:0 rgba(155, 89, 182, 0.7), stop:1 rgba(155, 89, 182, 0.5));
            transform: translateY(-1px);
            box-shadow: 0 4px 15px rgba(155, 89, 182, 0.3);
        }

        /* === 游戏模式卡片按钮样式 === */
        QPushButton#gameModeCard {
            background: qlineargradient(x1:0, y1:0, x2:1, y2:0,
                stop:0 rgba(255, 255, 255, 0.12), stop:1 rgba(255, 255, 255, 0.08));
            border: 2px solid rgba(255, 255, 255, 0.2);
            border-radius: 18px;
            text-align: left;
            padding: 0px;
            margin: 8px 0px;
        }

        QPushButton#gameModeCard:hover {
            background: qlineargradient(x1:0, y1:0, x2:1, y2:0,
                stop:0 rgba(76, 175, 80, 0.3), stop:1 rgba(76, 175, 80, 0.2));
            border: 2px solid rgba(76, 175, 80, 0.5);
            transform: translateY(-4px);
            box-shadow: 0 8px 25px rgba(76, 175, 80, 0.3);
        }

        QPushButton#gameModeCard:pressed {
            background: qlineargradient(x1:0, y1:0, x2:1, y2:0,
                stop:0 rgba(255, 255, 255, 0.08), stop:1 rgba(255, 255, 255, 0.04));
            transform: translateY(-1px);
        }

        /* === 模式按钮内部元素样式 === */
        QLabel#modeIcon {
            font-size: 28px;
            background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
                stop:0 rgba(76, 175, 80, 0.4), stop:1 rgba(76, 175, 80, 0.2));
            border-radius: 22px;
            border: 2px solid rgba(76, 175, 80, 0.6);
            color: #ffffff;
            font-weight: bold;
        }

        QLabel#modeTitle {
            font-size: 18px;
            font-weight: bold;
            color: #ffffff;
            margin: 0px;
            text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
        }

        QLabel#modeDescription {
            font-size: 13px;
            color: rgba(255, 255, 255, 0.85);
            margin: 0px;
            font-weight: 500;
        }

        QLabel#modeArrow {
            font-size: 16px;
            color: rgba(76, 175, 80, 0.8);
            font-weight: bold;
        }

        /* === 蛇展示区域样式 === */
        QWidget#snakeDisplay {
            background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
                stop:0 rgba(0, 0, 0, 0.3), stop:1 rgba(0, 0, 0, 0.1));
            border: 2px solid rgba(255, 255, 255, 0.1);
            border-radius: 15px;
            margin: 10px;
        }

        QLabel#snakeHead {
            background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
                stop:0 #4CAF50, stop:1 #45A049);
            border: 2px solid #2E7D32;
            border-radius: 18px;
            font-size: 16px;
            font-weight: bold;
            color: white;
        }

        QLabel#snakeBody {
            background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
                stop:0 #66BB6A, stop:1 #4CAF50);
            border: 1px solid #388E3C;
            border-radius: 15px;
            font-size: 14px;
            color: white;
        }

        QLabel#snakeTail {
            background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
                stop:0 #81C784, stop:1 #66BB6A);
            border: 1px solid #4CAF50;
            border-radius: 12px;
            font-size: 12px;
            color: white;
        }
    )");

    setStyleSheet(modernStyle);
    qDebug() << "SnakeGameEntryWidget: 现代化样式应用完成";
}

/**
 * @brief 设置右侧上部容器内容（功能按钮）
 * @param container 容器widget
 *
 * 包含排行榜、设置、帮助按钮
 */
void SnakeGameEntryWidget::setupRightTopContainer(QWidget *container)
{
    QHBoxLayout *layout = new QHBoxLayout(container);
    layout->setContentsMargins(15, 10, 15, 10);
    layout->setSpacing(15);

    // === 排行榜按钮 ===
    QPushButton *leaderboardBtn = new QPushButton("🏆 排行榜");
    leaderboardBtn->setObjectName("leaderboardButton");
    leaderboardBtn->setMinimumSize(100, 35);
    leaderboardBtn->setStyleSheet(
        "QPushButton {"
        "   background: rgba(52, 152, 219, 0.8);"
        "   color: white;"
        "   border: none;"
        "   border-radius: 6px;"
        "   font-size: 12px;"
        "   font-weight: bold;"
        "}"
        "QPushButton:hover {"
        "   background: rgba(52, 152, 219, 1.0);"
        "}"
    );

    // === 设置按钮 ===
    QPushButton *settingsBtn = new QPushButton("⚙️ 设置");
    settingsBtn->setObjectName("settingsButton");
    settingsBtn->setMinimumSize(80, 35);
    settingsBtn->setStyleSheet(
        "QPushButton {"
        "   background: rgba(149, 165, 166, 0.8);"
        "   color: white;"
        "   border: none;"
        "   border-radius: 6px;"
        "   font-size: 12px;"
        "   font-weight: bold;"
        "}"
        "QPushButton:hover {"
        "   background: rgba(149, 165, 166, 1.0);"
        "}"
    );

    // === 帮助按钮 ===
    QPushButton *helpBtn = new QPushButton("❓ 帮助");
    helpBtn->setObjectName("helpButton");
    helpBtn->setMinimumSize(80, 35);
    helpBtn->setStyleSheet(
        "QPushButton {"
        "   background: rgba(155, 89, 182, 0.8);"
        "   color: white;"
        "   border: none;"
        "   border-radius: 6px;"
        "   font-size: 12px;"
        "   font-weight: bold;"
        "}"
        "QPushButton:hover {"
        "   background: rgba(155, 89, 182, 1.0);"
        "}"
    );

    // === 连接信号（暂时显示提示）===
    connect(leaderboardBtn, &QPushButton::clicked, [this]() {
        QMessageBox::information(this, "排行榜", "排行榜功能即将推出！");
    });

    connect(settingsBtn, &QPushButton::clicked, [this]() {
        QMessageBox::information(this, "设置", "游戏设置功能即将推出！");
    });

    connect(helpBtn, &QPushButton::clicked, [this]() {
        QMessageBox::information(this, "帮助", "游戏帮助功能即将推出！");
    });

    // === 添加到布局 ===
    layout->addStretch();  // 左侧弹簧
    layout->addWidget(leaderboardBtn);
    layout->addWidget(settingsBtn);
    layout->addWidget(helpBtn);
}

/**
 * @brief 设置右侧中部容器内容（游戏模式选择）
 * @param container 容器widget
 *
 * 包含三个游戏模式：单人模式、多人模式、大逃杀模式
 */
void SnakeGameEntryWidget::setupRightMiddleContainer(QWidget *container)
{
    QVBoxLayout *layout = new QVBoxLayout(container);
    layout->setContentsMargins(0, 0, 0, 0);
    layout->setSpacing(0);

    // === 创建三个小容器，每个宽度100% ===

    // 单人模式容器
    QWidget *singlePlayerContainer = new QWidget();
    singlePlayerContainer->setObjectName("singlePlayerContainer");
    QHBoxLayout *singleLayout = new QHBoxLayout(singlePlayerContainer);
    singleLayout->setContentsMargins(0, 0, 0, 0);
    singleLayout->setSpacing(0);

    // === 创建现代化单人模式按钮 ===
    m_singlePlayerBtn = new QPushButton();
    m_singlePlayerBtn->setObjectName("modernGameModeCard");
    m_singlePlayerBtn->setMinimumHeight(100);
    m_singlePlayerBtn->setMaximumHeight(100);

    // 创建按钮内容布局
    QHBoxLayout *singleContentLayout = new QHBoxLayout(m_singlePlayerBtn);
    singleContentLayout->setContentsMargins(25, 20, 25, 20);
    singleContentLayout->setSpacing(20);

    // 图标
    QLabel *singleIcon = new QLabel("🎮");
    singleIcon->setObjectName("modernModeIcon");
    singleIcon->setFixedSize(50, 50);
    singleIcon->setAlignment(Qt::AlignCenter);
    singleIcon->setStyleSheet(
        "QLabel {"
        "   font-size: 32px;"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:1,"
        "       stop:0 rgba(76, 175, 80, 0.3), stop:1 rgba(76, 175, 80, 0.2));"
        "   border: 2px solid rgba(76, 175, 80, 0.6);"
        "   border-radius: 25px;"
        "   color: #ffffff;"
        "}"
    );

    // 文本区域
    QWidget *singleTextArea = new QWidget();
    QVBoxLayout *singleTextLayout = new QVBoxLayout(singleTextArea);
    singleTextLayout->setContentsMargins(0, 0, 0, 0);
    singleTextLayout->setSpacing(5);

    QLabel *singleTitle = new QLabel("单人模式");
    singleTitle->setObjectName("modernModeTitle");
    singleTitle->setStyleSheet(
        "QLabel {"
        "   font-size: 20px;"
        "   font-weight: bold;"
        "   color: #ffffff;"
        "   text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);"
        "}"
    );

    QLabel *singleDesc = new QLabel("挑战自己的极限");
    singleDesc->setObjectName("modernModeDescription");
    singleDesc->setStyleSheet(
        "QLabel {"
        "   font-size: 14px;"
        "   color: rgba(255, 255, 255, 0.85);"
        "   font-weight: 500;"
        "}"
    );

    singleTextLayout->addWidget(singleTitle);
    singleTextLayout->addWidget(singleDesc);

    // 箭头指示器
    QLabel *singleArrow = new QLabel("▶");
    singleArrow->setObjectName("modernModeArrow");
    singleArrow->setFixedSize(25, 25);
    singleArrow->setAlignment(Qt::AlignCenter);
    singleArrow->setStyleSheet(
        "QLabel {"
        "   font-size: 18px;"
        "   color: rgba(76, 175, 80, 0.8);"
        "   font-weight: bold;"
        "}"
    );

    singleContentLayout->addWidget(singleIcon);
    singleContentLayout->addWidget(singleTextArea, 1);
    singleContentLayout->addWidget(singleArrow);

    // 设置按钮样式
    m_singlePlayerBtn->setStyleSheet(
        "QPushButton#modernGameModeCard {"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
        "       stop:0 rgba(76, 175, 80, 0.15), stop:1 rgba(76, 175, 80, 0.1));"
        "   border: 2px solid rgba(76, 175, 80, 0.3);"
        "   border-radius: 20px;"
        "   text-align: left;"
        "   padding: 0px;"
        "   margin: 8px 0px;"
        "}"
        "QPushButton#modernGameModeCard:hover {"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
        "       stop:0 rgba(76, 175, 80, 0.25), stop:1 rgba(76, 175, 80, 0.2));"
        "   border: 2px solid rgba(76, 175, 80, 0.5);"
        "   transform: translateY(-2px);"
        "}"
        "QPushButton#modernGameModeCard:pressed {"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
        "       stop:0 rgba(76, 175, 80, 0.1), stop:1 rgba(76, 175, 80, 0.05));"
        "   transform: translateY(0px);"
        "}"
    );
    singleLayout->addWidget(m_singlePlayerBtn);

    // 多人模式容器
    QWidget *multiPlayerContainer = new QWidget();
    multiPlayerContainer->setObjectName("multiPlayerContainer");
    QHBoxLayout *multiLayout = new QHBoxLayout(multiPlayerContainer);
    multiLayout->setContentsMargins(0, 0, 0, 0);
    multiLayout->setSpacing(0);

    // === 创建现代化多人模式按钮 ===
    m_multiPlayerBtn = new QPushButton();
    m_multiPlayerBtn->setObjectName("modernGameModeCard");
    m_multiPlayerBtn->setMinimumHeight(100);
    m_multiPlayerBtn->setMaximumHeight(100);

    // 创建按钮内容布局
    QHBoxLayout *multiContentLayout = new QHBoxLayout(m_multiPlayerBtn);
    multiContentLayout->setContentsMargins(25, 20, 25, 20);
    multiContentLayout->setSpacing(20);

    // 图标
    QLabel *multiIcon = new QLabel("👥");
    multiIcon->setObjectName("modernModeIcon");
    multiIcon->setFixedSize(50, 50);
    multiIcon->setAlignment(Qt::AlignCenter);
    multiIcon->setStyleSheet(
        "QLabel {"
        "   font-size: 32px;"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:1,"
        "       stop:0 rgba(33, 150, 243, 0.3), stop:1 rgba(33, 150, 243, 0.2));"
        "   border: 2px solid rgba(33, 150, 243, 0.6);"
        "   border-radius: 25px;"
        "   color: #ffffff;"
        "}"
    );

    // 文本区域
    QWidget *multiTextArea = new QWidget();
    QVBoxLayout *multiTextLayout = new QVBoxLayout(multiTextArea);
    multiTextLayout->setContentsMargins(0, 0, 0, 0);
    multiTextLayout->setSpacing(5);

    QLabel *multiTitle = new QLabel("多人模式");
    multiTitle->setObjectName("modernModeTitle");
    multiTitle->setStyleSheet(
        "QLabel {"
        "   font-size: 20px;"
        "   font-weight: bold;"
        "   color: #ffffff;"
        "   text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);"
        "}"
    );

    QLabel *multiDesc = new QLabel("与其他玩家竞技");
    multiDesc->setObjectName("modernModeDescription");
    multiDesc->setStyleSheet(
        "QLabel {"
        "   font-size: 14px;"
        "   color: rgba(255, 255, 255, 0.85);"
        "   font-weight: 500;"
        "}"
    );

    multiTextLayout->addWidget(multiTitle);
    multiTextLayout->addWidget(multiDesc);

    // 箭头指示器
    QLabel *multiArrow = new QLabel("▶");
    multiArrow->setObjectName("modernModeArrow");
    multiArrow->setFixedSize(25, 25);
    multiArrow->setAlignment(Qt::AlignCenter);
    multiArrow->setStyleSheet(
        "QLabel {"
        "   font-size: 18px;"
        "   color: rgba(33, 150, 243, 0.8);"
        "   font-weight: bold;"
        "}"
    );

    multiContentLayout->addWidget(multiIcon);
    multiContentLayout->addWidget(multiTextArea, 1);
    multiContentLayout->addWidget(multiArrow);

    // 设置按钮样式
    m_multiPlayerBtn->setStyleSheet(
        "QPushButton#modernGameModeCard {"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
        "       stop:0 rgba(33, 150, 243, 0.15), stop:1 rgba(33, 150, 243, 0.1));"
        "   border: 2px solid rgba(33, 150, 243, 0.3);"
        "   border-radius: 20px;"
        "   text-align: left;"
        "   padding: 0px;"
        "   margin: 8px 0px;"
        "}"
        "QPushButton#modernGameModeCard:hover {"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
        "       stop:0 rgba(33, 150, 243, 0.25), stop:1 rgba(33, 150, 243, 0.2));"
        "   border: 2px solid rgba(33, 150, 243, 0.5);"
        "   transform: translateY(-2px);"
        "}"
        "QPushButton#modernGameModeCard:pressed {"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
        "       stop:0 rgba(33, 150, 243, 0.1), stop:1 rgba(33, 150, 243, 0.05));"
        "   transform: translateY(0px);"
        "}"
    );
    multiLayout->addWidget(m_multiPlayerBtn);

    // 大逃杀模式容器
    QWidget *battleRoyaleContainer = new QWidget();
    battleRoyaleContainer->setObjectName("battleRoyaleContainer");
    QHBoxLayout *battleLayout = new QHBoxLayout(battleRoyaleContainer);
    battleLayout->setContentsMargins(0, 0, 0, 0);
    battleLayout->setSpacing(0);

    // === 创建现代化大逃杀模式按钮 ===
    m_roomModeBtn = new QPushButton();
    m_roomModeBtn->setObjectName("modernGameModeCard");
    m_roomModeBtn->setMinimumHeight(100);
    m_roomModeBtn->setMaximumHeight(100);

    // 创建按钮内容布局
    QHBoxLayout *battleContentLayout = new QHBoxLayout(m_roomModeBtn);
    battleContentLayout->setContentsMargins(25, 20, 25, 20);
    battleContentLayout->setSpacing(20);

    // 图标
    QLabel *battleIcon = new QLabel("⚔️");
    battleIcon->setObjectName("modernModeIcon");
    battleIcon->setFixedSize(50, 50);
    battleIcon->setAlignment(Qt::AlignCenter);
    battleIcon->setStyleSheet(
        "QLabel {"
        "   font-size: 32px;"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:1,"
        "       stop:0 rgba(255, 87, 34, 0.3), stop:1 rgba(255, 87, 34, 0.2));"
        "   border: 2px solid rgba(255, 87, 34, 0.6);"
        "   border-radius: 25px;"
        "   color: #ffffff;"
        "}"
    );

    // 文本区域
    QWidget *battleTextArea = new QWidget();
    QVBoxLayout *battleTextLayout = new QVBoxLayout(battleTextArea);
    battleTextLayout->setContentsMargins(0, 0, 0, 0);
    battleTextLayout->setSpacing(5);

    QLabel *battleTitle = new QLabel("大逃杀模式");
    battleTitle->setObjectName("modernModeTitle");
    battleTitle->setStyleSheet(
        "QLabel {"
        "   font-size: 20px;"
        "   font-weight: bold;"
        "   color: #ffffff;"
        "   text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);"
        "}"
    );

    QLabel *battleDesc = new QLabel("多人生存竞技");
    battleDesc->setObjectName("modernModeDescription");
    battleDesc->setStyleSheet(
        "QLabel {"
        "   font-size: 14px;"
        "   color: rgba(255, 255, 255, 0.85);"
        "   font-weight: 500;"
        "}"
    );

    battleTextLayout->addWidget(battleTitle);
    battleTextLayout->addWidget(battleDesc);

    // 箭头指示器
    QLabel *battleArrow = new QLabel("▶");
    battleArrow->setObjectName("modernModeArrow");
    battleArrow->setFixedSize(25, 25);
    battleArrow->setAlignment(Qt::AlignCenter);
    battleArrow->setStyleSheet(
        "QLabel {"
        "   font-size: 18px;"
        "   color: rgba(255, 87, 34, 0.8);"
        "   font-weight: bold;"
        "}"
    );

    battleContentLayout->addWidget(battleIcon);
    battleContentLayout->addWidget(battleTextArea, 1);
    battleContentLayout->addWidget(battleArrow);

    // 设置按钮样式
    m_roomModeBtn->setStyleSheet(
        "QPushButton#modernGameModeCard {"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
        "       stop:0 rgba(255, 87, 34, 0.15), stop:1 rgba(255, 87, 34, 0.1));"
        "   border: 2px solid rgba(255, 87, 34, 0.3);"
        "   border-radius: 20px;"
        "   text-align: left;"
        "   padding: 0px;"
        "   margin: 8px 0px;"
        "}"
        "QPushButton#modernGameModeCard:hover {"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
        "       stop:0 rgba(255, 87, 34, 0.25), stop:1 rgba(255, 87, 34, 0.2));"
        "   border: 2px solid rgba(255, 87, 34, 0.5);"
        "   transform: translateY(-2px);"
        "}"
        "QPushButton#modernGameModeCard:pressed {"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
        "       stop:0 rgba(255, 87, 34, 0.1), stop:1 rgba(255, 87, 34, 0.05));"
        "   transform: translateY(0px);"
        "}"
    );
    battleLayout->addWidget(m_roomModeBtn);

    // === 删除：重复的信号连接，已在createGameModeCard中连接 ===

    // === 添加到布局（每个容器占相等高度）===
    layout->addWidget(singlePlayerContainer, 1);
    layout->addWidget(multiPlayerContainer, 1);
    layout->addWidget(battleRoyaleContainer, 1);
}

/**
 * @brief 设置右侧下部容器内容（游戏信息和状态）
 * @param container 容器widget
 *
 * 包含游戏状态、在线玩家、服务器状态等信息
 */
void SnakeGameEntryWidget::setupRightBottomContainer(QWidget *container)
{
    QHBoxLayout *layout = new QHBoxLayout(container);
    layout->setContentsMargins(15, 10, 15, 10);
    layout->setSpacing(20);

    // === 游戏状态信息 ===
    QLabel *statusLabel = new QLabel("🎮 Snake Game");
    statusLabel->setObjectName("gameStatusLabel");
    statusLabel->setStyleSheet(
        "QLabel {"
        "   color: #4CAF50;"
        "   font-size: 18px;"
        "   font-weight: bold;"
        "}"
    );

    // === 在线玩家信息 ===
    QLabel *playersLabel = new QLabel("👥 在线玩家: 1,234");
    playersLabel->setObjectName("playersLabel");
    playersLabel->setStyleSheet(
        "QLabel {"
        "   color: #ECF0F1;"
        "   font-size: 14px;"
        "}"
    );

    // === 服务器状态 ===
    QLabel *serverLabel = new QLabel("🟢 服务器正常");
    serverLabel->setObjectName("serverLabel");
    serverLabel->setStyleSheet(
        "QLabel {"
        "   color: #2ECC71;"
        "   font-size: 14px;"
        "}"
    );

    // === 添加到布局 ===
    layout->addWidget(statusLabel);
    layout->addStretch();  // 弹簧
    layout->addWidget(playersLabel);
    layout->addWidget(serverLabel);
}
